<?php
/**
 * @Name: BaseSearch.php
 * @Author: yashuai
 */

namespace App\Http\Search;

use HugCode\PhpUnits\InstanceTool;

class BaseSearch
{

    use InstanceTool;

    protected $query;

    /**
     * @Desc 查询分页列表
     * @return array
     * @author yashuai
     */
    protected function pageList()
    {
        if (_array_field($this->params, 'IsPage', false) === 'no') {
            return $this->query->get()->toArray();
        } else {
            $limit = _array_field($this->params, 'Size', 20);
            $page  = _array_field($this->params, 'Page', 1);
            return [
                'count' => $this->query->count(),
                'list'  => $this->query->limit($limit)->offset(($page - 1) * $limit)->get()->toArray(),
            ];
        }
    }

}
